package com.jandar.controller;

import com.alibaba.fastjson.JSONObject;
import com.cl.mvc.controller.BaseController;
import com.cl.mvc.service.BaseService;
import com.jandar.entity.ExcelSourceType;
import com.jandar.entity.ExcelSourceTypeField;
import com.jandar.entity.ExcelSourceTypeMapping;
import com.querydsl.jpa.impl.JPAQueryFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.jandar.constant.QTableConstant.qExcelSourceType;
import static com.jandar.constant.QTableConstant.qExcelSourceTypeMapping;


@RestController
@RequestMapping("ExcelSourceType")
public class ExcelSourceTypeController extends BaseController<ExcelSourceType> {
    @Autowired
    JPAQueryFactory queryFactory;

    public ExcelSourceTypeController(BaseService<ExcelSourceType> service) {
        super(service);
    }

    //
//
//    @GetMapping("/listTypeAll")
//    public JSONObject listTypeAll() {
//        JSONObject jsonObject = new JSONObject();
//        List<ExcelSourceType> type = dslContext.selectFrom(EXCEL_SOURCE_TYPE).fetchInto(ExcelSourceType.class);
//        jsonObject.put("data", type);
//        jsonObject.put("status", true);
//        jsonObject.put("msg", "成功");
//        return jsonObject;
//    }
//
//    @GetMapping("/listType")
//    public JSONObject listType() {
//        JSONObject jsonObject = new JSONObject();
//        List<ExcelSourceType> type = queryFactory.selectFrom(qExcelSourceType).where(qExcelSourceType.parentId.isNull()).fetch();
//        jsonObject.put("data", type);
//        jsonObject.put("status", true);
//        jsonObject.put("msg", "成功");
//        return jsonObject;
//    }
////
//    @GetMapping("/listTypeMapping")
//    public JSONObject listTypeMapping(Integer typeId, String typeName) {
//        JSONObject jsonObject = new JSONObject();
//        if (typeId == null) {
//            typeId = queryFactory.select(qExcelSourceType.id).from(qExcelSourceType).where(qExcelSourceType.name.eq(typeName)).fetchOne();
//        }
//        List<ExcelSourceTypeMapping> types = queryFactory.selectFrom(qExcelSourceTypeMapping).where(qExcelSourceTypeMapping.typeId.eq(typeId)).fetch();
//        jsonObject.put("data", types);
//        jsonObject.put("status", true);
//        jsonObject.put("msg", "成功");
//        return jsonObject;
//    }
}
